package mastermind.gui;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import mastermind.gui.actions.SendRegisterAction;
import mastermind.socket.socketConnect;

public class RegisterFrame extends JFrame{
	
	private JLabel lblFname;
	private JLabel lblSname;
	private JLabel lblUsername;
	private JLabel lblPassword;
	private JLabel lblPhno;
	
	private JTextField txtFname;
	private JTextField txtSname;
	private JTextField txtUsername;
	private JTextField txtPassword;
	private JTextField txtPhno;
	
	private JButton btnRegister;
	private Action sendRegister;
	
	private JPanel topPanel;
	
	private Frame frame;
	
	/**
	 * get first name for register
	 */
	public String getFirstName()
	{
		return txtFname.getText();
	}
	
	/**
	 * get surname for register
	 */
	public String getSurname()
	{
		return txtSname.getText();
	}
	
	/**
	 * get username for register
	 */
	public String getUsername()
	{
		return txtUsername.getText();
	}
	
	/**
	 * get password for register
	 */
	public String getPassword()
	{
		return txtPassword.getText();
	}
	
	/**
	 * get phone number for register
	 */
	public String getPhno()
	{
		return txtPhno.getText();
	}
	
	/**
	 * get connected socket
	 */
	public socketConnect getSocket()
	{
		return frame.connect();
	}
	
	public RegisterFrame(Frame frame) {
		
		this.frame = frame;
		sendRegister = new SendRegisterAction(this);
		
		topPanel = new JPanel();
    	topPanel.setPreferredSize(new Dimension(200,200));
    	topPanel.setLayout(new GridLayout(6,2));
    	this.getContentPane().add(topPanel);
    	
    	lblFname = new JLabel("First Name:");
    	lblSname = new JLabel("Last Name:");
    	lblUsername = new JLabel("Username:");
    	lblPassword = new JLabel("Password:");
    	lblPhno = new JLabel("Phone Number:");
    	
    	txtFname = new JTextField();
    	txtSname = new JTextField();
    	txtUsername = new JTextField();
    	txtPassword = new JTextField();
    	txtPhno = new JTextField();
    	
    	btnRegister = new JButton(sendRegister);
    	btnRegister.setText("Register");
    	
    	topPanel.add(lblFname);
    	topPanel.add(txtFname);
    	topPanel.add(lblSname);
    	topPanel.add(txtSname);  //create components and add them to panels
    	topPanel.add(lblUsername);
    	topPanel.add(txtUsername);
    	topPanel.add(lblPassword);
    	topPanel.add(txtPassword);
    	topPanel.add(lblPhno);
    	topPanel.add(txtPhno);
    	topPanel.add(btnRegister);
    	
    	this.setResizable(false);
    	this.setSize(200,200);
    	this.setLocationRelativeTo(null);
    	this.setTitle("Register");
    	
		
	}

}
